# __init__.py
import os
import logging

# 版本信息
VERSION = "v0.0.0"

# 开发人员可调参数
EDGE_MARGIN = 200
SHOW_EDGE = False
INTERVAL_FRAME = 1
DISPLAY_INPUT = False
DISPLAY_SCALE_FACTOR = 0.8
DISPLAY_FLAG = False
DISPLAY_SAVE_FLAG = True
DISPLAY_SAVE_NAME = "flow_count-test.mp4"
DISPLAY_PUSH = True

# 路径配置
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) # 获取当前文件（__init__.py）所在的目录: ./vehicle_flow_counting/
CONFIG_FILE = os.path.join(BASE_DIR, "config.yaml") # 配置文件路径
MODEL_FILE = os.path.join(BASE_DIR, "model", "yolo11m-obb-visdrone-0.pt") # 模型文件路径
V_OUT_FILE = os.path.join(BASE_DIR, "zzz", DISPLAY_SAVE_NAME) # 输出视频保存路径
os.makedirs(os.path.dirname(V_OUT_FILE), exist_ok=True) # 确保 run 目录存在
LOG_FILE = os.path.join(BASE_DIR, "algorithm.log") # 日志文件路径

# 日志配置
LOG_LEVEL = logging.INFO  # 可选: DEBUG, INFO, WARNING, ERROR, CRITICAL
# 统一配置根 Logger
if not logging.getLogger().handlers: # 如果在别的地方再次 import vehicle_flow_counting，logging 可能重复写入，所以在 basicConfig 之前加个判断
    logging.basicConfig(
        level=LOG_LEVEL,
        # format='[%(levelname)s] %(asctime)s - %(filename)s:%(lineno)d - %(message)s',
        format='[%(levelname)s] %(asctime)s - %(filename)s - %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S',
        handlers=[
            logging.FileHandler(LOG_FILE, encoding="utf-8"), # encoding 解决日志文件中文乱码的关键参数
            logging.StreamHandler()
        ],
    #     force=True  # 强制生效 覆盖其他的全局配置
    )

# 类别映射（按数据集定义来）
CLASS_NAMES = {
    0: "pedestrian",
    1: "people",
    2: "bicycle",
    3: "car",
    4: "van",
    5: "truck",
    6: "tricycle",
    7: "awning-tricycle",
    8: "bus",
    9: "motor"
}


# from .detector import YoloTracker
# from .counter import FlowCounter, COLORS
# from .utils.video_io import VideoIO
# from .utils.config_loader import load_config
# from .utils.frame_display import show_frame_scaled

# ==========================================
# 对外统一接口
# ==========================================
# __all__ = [
#     # 常量与路径
#     "VERSION", "EDGE_MARGIN", "SHOW_EDGE", "INTERVAL_FRAME", "DISPLAY_INPUT", "DISPLAY_SCALE_FACTOR", "DISPLAY_FLAG", "DISPLAY_SAVE_FLAG", "DISPLAY_SEND", "BASE_DIR", "CONFIG_FILE", "MODEL_FILE", "LOG_FILE", "V_OUT_FILE", "CLASS_NAMES", "COLORS",
#     # 类
#     "YoloTracker", "FlowCounter", "VideoIO",
#     # 函数
#     "load_config", "show_frame_scaled",
# ]

# 子模块添加：
# import logging
# logger = logging.getLogger(__name__) # 继承全局配置
# logger.debug("DEBUG")
# logger.info("INFO")
# logger.warning("WARNING")
# logger.error("ERROR")
# logger.critical("CRITICAL")

# ~/code/python/cv$ python -B -m vehicle_flow_counting.utils.model_crypto
# ~/code/python/cv$ python -B -m vehicle_flow_counting.main


# class_names_coco = {
#     0: "person", 1: "bicycle", 2: "car", 3: "motorcycle", 4: "airplane", 5: "bus", 6: "train", 7: "truck", 8: "boat", 9: "traffic light",
#     10: "fire hydrant", 11: "stop sign", 12: "parking meter", 13: "bench", 14: "bird", 15: "cat", 16: "dog", 17: "horse", 18: "sheep", 19: "cow",
#     20: "elephant", 21: "bear", 22: "zebra", 23: "giraffe", 24: "backpack", 25: "umbrella", 26: "handbag", 27: "tie", 28: "suitcase", 29: "frisbee",
#     30: "skis", 31: "snowboard", 32: "sports ball", 33: "kite", 34: "baseball bat", 35: "baseball glove", 36: "skateboard", 37: "surfboard", 38: "tennis racket", 39: "bottle",
#     40: "wine glass", 41: "cup", 42: "fork", 43: "knife", 44: "spoon", 45: "bowl", 46: "banana", 47: "apple", 48: "sandwich", 49: "orange",
#     50: "broccoli", 51: "carrot", 52: "hot dog", 53: "pizza", 54: "donut", 55: "cake", 56: "chair", 57: "couch", 58: "potted plant", 59: "bed",
#     60: "dining table", 61: "toilet", 62: "tv", 63: "laptop", 64: "mouse", 65: "remote", 66: "keyboard", 67: "cell phone", 68: "microwave", 69: "oven",
#     70: "toaster", 71: "sink", 72: "refrigerator", 73: "book", 74: "clock", 75: "vase", 76: "scissors", 77: "teddy bear", 78: "hair drier", 79: "toothbrush"
# }
# classes_coco = [
#     0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
#     10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
#     20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
#     30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
#     40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
#     50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
#     60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
#     70, 71, 72, 73, 74, 75, 76, 77, 78, 79
# ]
